from flask import render_template
from .models import News

#视图函数

def index():
    """ 新闻首页 """
    news_list = News.objects.filter(is_valid=True)
    print(news_list.count)
    return render_template("index.html", news_list=news_list)


def cat(name):
    """ 新闻类别页面 """
    news_list = News.objects.filter(is_valid=True, news_type=name)
    return render_template('cat.html', name=name, news_list=news_list)


def detail(pk):
    """ 新闻详情页 """
    new_obj = News.objects.filter(pk=pk).first()
    return render_template('detail.html', new_obj=new_obj)

